package m202401.d08;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/1/8 09:42
 */
//104. 二叉树的最大深度
public class Q104 {

    private int maxDepth;

    public int maxDepth(TreeNode root) {
        maxDepth = 0;
        travel(root, 0);
        return maxDepth;
    }

    public void travel(TreeNode node, int depth) {
        if (node == null) {
            maxDepth = Math.max(depth, maxDepth);
            return;
        }
        travel(node.left, depth + 1);
        travel(node.right, depth + 1);
    }


    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

}
